public class Solution_242 {
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        int[] m = new int[27];
        for (int i = 0; i < s.length(); i++) {
            m[s.charAt(i) - 'a'] += 1;
        }

        for (int i = 0; i < t.length(); i++) {
            m[t.charAt(i) - 'a'] -= 1;
            if (m[t.charAt(i) - 'a'] < 0) return false;
        }


        return true;
    }
    
    public static void main(String[] args) {
        String s = "anagram", t = "nagaram";
        System.out.println(new Solution_242().isAnagram(s, t));
    }
    
    
}
